package com.info.zhiduoduo.common.excelconverter;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.info.zhiduoduo.common.constants.crowdsource.CrowdsourceUserType;
import com.info.zhiduoduo.common.utils.StringUtil;

/**
 * @program: zhiduoduo
 * @author: LiTong
 * @create: 2020-12-09 14:39
 **/
public class UserTypeConverter implements Converter<Integer> {

    @Override
    public Class supportJavaTypeKey() {
        return null;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return null;
    }

    @Override
    public Integer convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        String value = cellData.getStringValue();
        if (StringUtil.equals(value, "自然人")) return CrowdsourceUserType.NATURAL_PERSON;
        if (StringUtil.equals(value, "创客")) return CrowdsourceUserType.STUDIO;
        return 0;
    }

    @Override
    public CellData convertToExcelData(Integer value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        if (value == null) {
            return new CellData("");
        } else if (value == CrowdsourceUserType.NATURAL_PERSON) {
            return new CellData("自然人");
        } else if (value == CrowdsourceUserType.STUDIO) {
            return new CellData("创客");
        } else {
            return new CellData("");
        }
    }
}
